reflect: add TypeAssert[T]#71639
Conversation
10ff4ad to
b35a231
Compare
|
This PR (HEAD: b35a231) has been imported to Gerrit for code review. Please visit Gerrit at https://go-review.googlesource.com/c/go/+/648056. Important tips:
|
|
Message from Mateusz Poliwczak: Patch Set 1: Commit-Queue+1 Please don’t reply on this GitHub thread. Visit golang.org/cl/648056. |
|
Message from Go LUCI: Patch Set 1: Dry run: CV is trying the patch. Bot data: {"action":"start","triggered_at":"2025-02-10T15:07:38Z","revision":"22213209ba3888233ea8cf82cac5372c6ae695ba"} Please don’t reply on this GitHub thread. Visit golang.org/cl/648056. |
|
Message from Mateusz Poliwczak: Patch Set 1: (1 comment) Please don’t reply on this GitHub thread. Visit golang.org/cl/648056. |
|
Message from Mateusz Poliwczak: Patch Set 1: -Commit-Queue Please don’t reply on this GitHub thread. Visit golang.org/cl/648056. |
|
Message from Go LUCI: Patch Set 1: This CL has passed the run Please don’t reply on this GitHub thread. Visit golang.org/cl/648056. |
|
Message from Go LUCI: Patch Set 1: LUCI-TryBot-Result+1 Please don’t reply on this GitHub thread. Visit golang.org/cl/648056. |
|
This PR (HEAD: eb46a00) has been imported to Gerrit for code review. Please visit Gerrit at https://go-review.googlesource.com/c/go/+/648056. Important tips:
|
|
Message from Mateusz Poliwczak: Patch Set 2: Commit-Queue+1 (1 comment) Please don’t reply on this GitHub thread. Visit golang.org/cl/648056. |
|
Message from Go LUCI: Patch Set 2: Dry run: CV is trying the patch. Bot data: {"action":"start","triggered_at":"2025-02-11T11:34:47Z","revision":"8b4456e086f834a678828b5abf3f4f4fc7606e38"} Please don’t reply on this GitHub thread. Visit golang.org/cl/648056. |
|
Message from Mateusz Poliwczak: Patch Set 2: -Commit-Queue Please don’t reply on this GitHub thread. Visit golang.org/cl/648056. |
|
Message from Go LUCI: Patch Set 2: This CL has failed the run. Reason: Tryjob golang/try/gotip-linux-amd64-misccompile has failed with summary (view all results):
Error: Additional links for debugging:
Please don’t reply on this GitHub thread. Visit golang.org/cl/648056. |
|
Message from Go LUCI: Patch Set 2: LUCI-TryBot-Result-1 Please don’t reply on this GitHub thread. Visit golang.org/cl/648056. |
|
This PR (HEAD: e452d77) has been imported to Gerrit for code review. Please visit Gerrit at https://go-review.googlesource.com/c/go/+/648056. Important tips:
|
|
Message from Mateusz Poliwczak: Patch Set 3: Commit-Queue+1 Please don’t reply on this GitHub thread. Visit golang.org/cl/648056. |
|
Message from Go LUCI: Patch Set 3: Dry run: CV is trying the patch. Bot data: {"action":"start","triggered_at":"2025-02-11T13:38:42Z","revision":"4e5f8f42e60d3744eb95f2e0feb24c6072a333e5"} Please don’t reply on this GitHub thread. Visit golang.org/cl/648056. |
|
Message from Mateusz Poliwczak: Patch Set 3: -Commit-Queue Please don’t reply on this GitHub thread. Visit golang.org/cl/648056. |
|
Message from Go LUCI: Patch Set 3: This CL has passed the run Please don’t reply on this GitHub thread. Visit golang.org/cl/648056. |
|
Message from Go LUCI: Patch Set 3: LUCI-TryBot-Result+1 Please don’t reply on this GitHub thread. Visit golang.org/cl/648056. |
|
This PR (HEAD: e79e2ea) has been imported to Gerrit for code review. Please visit Gerrit at https://go-review.googlesource.com/c/go/+/648056. Important tips:
|
|
Message from Ian Lance Taylor: Patch Set 4: Commit-Queue+1 Please don’t reply on this GitHub thread. Visit golang.org/cl/648056. |
|
Message from Go LUCI: Patch Set 4: Dry run: CV is trying the patch. Bot data: {"action":"start","triggered_at":"2025-02-11T17:15:10Z","revision":"679b59c33ef6a9ae28e4227314632fdef56d5e27"} Please don’t reply on this GitHub thread. Visit golang.org/cl/648056. |
|
Message from Mateusz Poliwczak: Patch Set 4: (1 comment) Please don’t reply on this GitHub thread. Visit golang.org/cl/648056. |
|
Message from Ian Lance Taylor: Patch Set 4: -Commit-Queue Please don’t reply on this GitHub thread. Visit golang.org/cl/648056. |
|
Message from Go LUCI: Patch Set 4: This CL has passed the run Please don’t reply on this GitHub thread. Visit golang.org/cl/648056. |
|
Message from Go LUCI: Patch Set 4: LUCI-TryBot-Result+1 Please don’t reply on this GitHub thread. Visit golang.org/cl/648056. |
e79e2ea to
83c22e1
Compare
|
This PR (HEAD: 83c22e1) has been imported to Gerrit for code review. Please visit Gerrit at https://go-review.googlesource.com/c/go/+/648056. Important tips:
|
83c22e1 to
cff1e5c
Compare
|
Message from Mateusz Poliwczak: Patch Set 9: -Commit-Queue Please don’t reply on this GitHub thread. Visit golang.org/cl/648056. |
|
Message from Go LUCI: Patch Set 9: This CL has failed the run. Reason: Tryjob golang/try/gotip-wasip1-wasm_wasmtime has failed with summary (view all results):
To reproduce, try Additional links for debugging: Please don’t reply on this GitHub thread. Visit golang.org/cl/648056. |
|
Message from Mateusz Poliwczak: Patch Set 9: (1 comment) Please don’t reply on this GitHub thread. Visit golang.org/cl/648056. |
Change-Id: Ib84e1f9f557c5a0605ebacdcf57b2f488a7ab186
Change-Id: Iae78e5cc2ca10468d2084e9caa8918792af9be83
2ab425a to
c2b7923
Compare
|
This PR (HEAD: c2b7923) has been imported to Gerrit for code review. Please visit Gerrit at https://go-review.googlesource.com/c/go/+/648056. Important tips:
|
|
Message from Mateusz Poliwczak: Patch Set 10: Commit-Queue+1 (1 comment) Please don’t reply on this GitHub thread. Visit golang.org/cl/648056. |
|
Message from Go LUCI: Patch Set 10: Dry run: CV is trying the patch. Bot data: {"action":"start","triggered_at":"2025-05-20T15:09:56Z","revision":"b5756cc76c689fe22ae54bf8dd46844015f19f2f"} Please don’t reply on this GitHub thread. Visit golang.org/cl/648056. |
|
Message from Cherry Mui: Patch Set 10: Code-Review+2 (2 comments) Please don’t reply on this GitHub thread. Visit golang.org/cl/648056. |
Change-Id: I2b035a17ce7479ea47d247deafbc8b4ee23ee442
|
This PR (HEAD: ce89a53) has been imported to Gerrit for code review. Please visit Gerrit at https://go-review.googlesource.com/c/go/+/648056. Important tips:
|
|
Message from Go LUCI: Patch Set 10: LUCI-TryBot-Result-1 Please don’t reply on this GitHub thread. Visit golang.org/cl/648056. |
|
Message from Mateusz Poliwczak: Patch Set 11: Commit-Queue+1 (1 comment) Please don’t reply on this GitHub thread. Visit golang.org/cl/648056. |
|
Message from Go LUCI: Patch Set 11: Dry run: CV is trying the patch. Bot data: {"action":"start","triggered_at":"2025-05-20T15:42:25Z","revision":"a4c446d69f496eb31367985d21681f9fd0767af0"} Please don’t reply on this GitHub thread. Visit golang.org/cl/648056. |
|
Message from Cherry Mui: Patch Set 11: Code-Review+2 (1 comment) Please don’t reply on this GitHub thread. Visit golang.org/cl/648056. |
|
Message from Keith Randall: Patch Set 11: Code-Review+1 Please don’t reply on this GitHub thread. Visit golang.org/cl/648056. |
|
Message from Mateusz Poliwczak: Patch Set 11: -Commit-Queue Please don’t reply on this GitHub thread. Visit golang.org/cl/648056. |
|
Message from Go LUCI: Patch Set 11: This CL has passed the run Please don’t reply on this GitHub thread. Visit golang.org/cl/648056. |
|
Message from Go LUCI: Patch Set 11: LUCI-TryBot-Result+1 Please don’t reply on this GitHub thread. Visit golang.org/cl/648056. |
|
Message from Mateusz Poliwczak: Patch Set 11: (1 comment) Please don’t reply on this GitHub thread. Visit golang.org/cl/648056. |
This implementation is zero-alloc when T is a concrete type,
allocates when val contains a method or when T is a interface
and Value was obtained for example through Elem(), in which case
it has to be allocated to avoid sharing the same memory.
goos: linux
goarch: amd64
pkg: reflect
cpu: AMD Ryzen 5 4600G with Radeon Graphics
│ /tmp/bench2 │
│ sec/op │
TypeAssert/TypeAssert[int](int)-12 2.725n ± 1%
TypeAssert/TypeAssert[uint8](int)-12 2.599n ± 1%
TypeAssert/TypeAssert[fmt.Stringer](reflect_test.testTypeWithMethod)-12 8.470n ± 0%
TypeAssert/TypeAssert[fmt.Stringer](*reflect_test.testTypeWithMethod)-12 8.460n ± 1%
TypeAssert/TypeAssert[interface_{}](int)-12 4.181n ± 1%
TypeAssert/TypeAssert[interface_{}](reflect_test.testTypeWithMethod)-12 4.178n ± 1%
TypeAssert/TypeAssert[time.Time](time.Time)-12 2.839n ± 0%
TypeAssert/TypeAssert[func()_string](func()_string)-12 151.1n ± 1%
geomean 6.645n
│ /tmp/bench2 │
│ B/op │
TypeAssert/TypeAssert[int](int)-12 0.000 ± 0%
TypeAssert/TypeAssert[uint8](int)-12 0.000 ± 0%
TypeAssert/TypeAssert[fmt.Stringer](reflect_test.testTypeWithMethod)-12 0.000 ± 0%
TypeAssert/TypeAssert[fmt.Stringer](*reflect_test.testTypeWithMethod)-12 0.000 ± 0%
TypeAssert/TypeAssert[interface_{}](int)-12 0.000 ± 0%
TypeAssert/TypeAssert[interface_{}](reflect_test.testTypeWithMethod)-12 0.000 ± 0%
TypeAssert/TypeAssert[time.Time](time.Time)-12 0.000 ± 0%
TypeAssert/TypeAssert[func()_string](func()_string)-12 72.00 ± 0%
geomean ¹
Fixes #62121
Change-Id: I0911c70c5966672c930d387438643f94a40441c4
GitHub-Last-Rev: ce89a53
GitHub-Pull-Request: #71639
Reviewed-on: https://go-review.googlesource.com/c/go/+/648056
LUCI-TryBot-Result: Go LUCI <[email protected]>
Reviewed-by: Keith Randall <[email protected]>
Reviewed-by: Cherry Mui <[email protected]>
|
This PR is being closed because golang.org/cl/648056 has been merged. |
This implementation is zero-alloc when T is a concrete type,
allocates when val contains a method or when T is a interface
and Value was obtained for example through Elem(), in which case
it has to be allocated to avoid sharing the same memory.
goos: linux
goarch: amd64
pkg: reflect
cpu: AMD Ryzen 5 4600G with Radeon Graphics
│ /tmp/bench2 │
│ sec/op │
TypeAssert/TypeAssert[int](int)-12 2.725n ± 1%
TypeAssert/TypeAssert[uint8](int)-12 2.599n ± 1%
TypeAssert/TypeAssert[fmt.Stringer](reflect_test.testTypeWithMethod)-12 8.470n ± 0%
TypeAssert/TypeAssert[fmt.Stringer](*reflect_test.testTypeWithMethod)-12 8.460n ± 1%
TypeAssert/TypeAssert[interface_{}](int)-12 4.181n ± 1%
TypeAssert/TypeAssert[interface_{}](reflect_test.testTypeWithMethod)-12 4.178n ± 1%
TypeAssert/TypeAssert[time.Time](time.Time)-12 2.839n ± 0%
TypeAssert/TypeAssert[func()_string](func()_string)-12 151.1n ± 1%
geomean 6.645n
│ /tmp/bench2 │
│ B/op │
TypeAssert/TypeAssert[int](int)-12 0.000 ± 0%
TypeAssert/TypeAssert[uint8](int)-12 0.000 ± 0%
TypeAssert/TypeAssert[fmt.Stringer](reflect_test.testTypeWithMethod)-12 0.000 ± 0%
TypeAssert/TypeAssert[fmt.Stringer](*reflect_test.testTypeWithMethod)-12 0.000 ± 0%
TypeAssert/TypeAssert[interface_{}](int)-12 0.000 ± 0%
TypeAssert/TypeAssert[interface_{}](reflect_test.testTypeWithMethod)-12 0.000 ± 0%
TypeAssert/TypeAssert[time.Time](time.Time)-12 0.000 ± 0%
TypeAssert/TypeAssert[func()_string](func()_string)-12 72.00 ± 0%
geomean ¹
Fixes golang#62121
Change-Id: I0911c70c5966672c930d387438643f94a40441c4
GitHub-Last-Rev: ce89a53
GitHub-Pull-Request: golang#71639
Reviewed-on: https://go-review.googlesource.com/c/go/+/648056
LUCI-TryBot-Result: Go LUCI <[email protected]>
Reviewed-by: Keith Randall <[email protected]>
Reviewed-by: Cherry Mui <[email protected]>
This implementation is zero-alloc when T is a concrete type,
allocates when val contains a method or when T is a interface
and Value was obtained for example through Elem(), in which case
it has to be allocated to avoid sharing the same memory.
goos: linux
goarch: amd64
pkg: reflect
cpu: AMD Ryzen 5 4600G with Radeon Graphics
│ /tmp/bench2 │
│ sec/op │
TypeAssert/TypeAssertint-12 2.725n ± 1%
TypeAssert/TypeAssertuint8-12 2.599n ± 1%
TypeAssert/TypeAssertfmt.Stringer-12 8.470n ± 0%
TypeAssert/TypeAssertfmt.Stringer-12 8.460n ± 1%
TypeAssert/TypeAssertinterface_{}-12 4.181n ± 1%
TypeAssert/TypeAssertinterface_{}-12 4.178n ± 1%
TypeAssert/TypeAsserttime.Time-12 2.839n ± 0%
TypeAssert/TypeAssertfunc()_string-12 151.1n ± 1%
geomean 6.645n
TypeAssert/TypeAssertint-12 0.000 ± 0%
TypeAssert/TypeAssertuint8-12 0.000 ± 0%
TypeAssert/TypeAssertfmt.Stringer-12 0.000 ± 0%
TypeAssert/TypeAssertfmt.Stringer-12 0.000 ± 0%
TypeAssert/TypeAssertinterface_{}-12 0.000 ± 0%
TypeAssert/TypeAssertinterface_{}-12 0.000 ± 0%
TypeAssert/TypeAsserttime.Time-12 0.000 ± 0%
TypeAssert/TypeAssertfunc()_string-12 72.00 ± 0%
geomean ¹
Fixes #62121